package com.tsh.chat.mapper;
import com.tsh.chat.domain.ChatHistory;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChatHistoryMapper {
    @Select("SELECT * FROM tsh_chat_history WHERE user_id = #{userId} ORDER BY id")
    List<ChatHistory> findByUserId(int userId);

    @Insert("INSERT INTO tsh_chat_history (user_id, role, content) VALUES (#{user_id}, #{role}, #{content})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(ChatHistory chatHistory);

    @Update("UPDATE tsh_chat_history SET role = #{role}, content = #{content} WHERE id = #{id}")
    int update(ChatHistory chatHistory);

    @Delete("DELETE FROM tsh_chat_history WHERE user_id = #{userId}")
    int deleteByUserId(int userId);

    @Delete("DELETE FROM tsh_chat_history")
    int deleteAll();
}